package com.zg.scf.web;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zg.common.core.R;

import com.zg.scf.domain.convert.AccAccountConvert;
import com.zg.scf.domain.req.account.*;
import com.zg.scf.domain.vo.AccAccountVo;
import com.zg.scf.service.AccAccountService;
import com.zg.scf.util.DataScopeUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>Description: </p>
 *
 * @author zhanfeng.liang
 * @since 2025/5/22 10:54
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/scf/account")
@Slf4j
@Api(tags = "企业账户管理")
public class AccAccountController {
    private final AccAccountService accAccountService;

    private final AccAccountConvert accAccountConvert;


    private final DataScopeUtil dataScopeUtil;

    @PostMapping("/page")
    @ApiOperation(value = "后管查询账户")
    public R<Page<AccAccountVo>> page(@RequestBody AccAccountPageReq pageReq) {
        Page<AccAccountVo> page = accAccountService.page(pageReq,AccAccountVo.class);
        return R.success(page);
    }

    @PostMapping("/pageForCompany")
    @ApiOperation(value = "融资企业查询账户")
    public R<Page<AccAccountVo>> pageForCompany(@RequestBody AccAccountPageReq pageReq) {
        Long companyId =dataScopeUtil.getOrgDataScope();
        pageReq.setCompanyId(companyId);
        Page<AccAccountVo> page = accAccountService.page(pageReq,AccAccountVo.class);
        return R.success(page);
    }
    @PostMapping("/add")
    @ApiOperation(value = "管理员添加账户")
    public R add(@RequestBody @Valid AccAccountAddReq addReq) {
        accAccountService.add(addReq);
        return R.success();
    }

    @PostMapping("/addForCompany")
    @ApiOperation(value = "融资企业添加账户")
    public R addForCompany(@RequestBody @Valid AccAccountAddReq addReq) {
        Long companyId =dataScopeUtil.getOrgDataScope();
        addReq.setCompanyId(companyId);
        accAccountService.add(addReq);
        return R.success();
    }

    @PostMapping("/edit")
    @ApiOperation(value = "修改账户")
    public R edit(@RequestBody @Valid AccAccountEditReq editReq) {
        accAccountService.edit(editReq);
        return R.success();
    }
    @PostMapping("/editSort")
    @ApiOperation(value = "修改默认账户")
    public R editSort(@RequestBody @Valid AccAccountEditSortReq editReq) {
        accAccountService.editSort(editReq);
        return R.success();
    }

    @PostMapping("/editState")
    @ApiOperation(value = "修改账户状态")
    public R editState(@RequestBody @Valid AccAccountEditStateReq editReq) {
        accAccountService.editState(editReq);
        return R.success();
    }

    @PostMapping("/syncBalance")
    @ApiOperation(value = "同步银行账户")
    public R syncBalance(@RequestParam("accountId") Long accountId) {
        accAccountService.syncBalance(accountId);
        return R.success();
    }

    @PostMapping("/remove")
    @ApiOperation(value = "删除账户")
    public R remove(@RequestBody  List<Long> ids) {
        accAccountService.remove(ids);
        return R.success();
    }
}
